package com.huoyun.car.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.huoyun.base.dao.BaseDaoImpl;
import com.huoyun.car.bean.Driver;

public class DriverDaoImpl extends BaseDaoImpl<Driver> implements DriverDao {

	public void saveDriver(Driver driver) {
		this.sqlSessionTemplate.insert("com.huoyun.car.dao.DriverDaoMapper.saveDriver", driver);
	}

	public void updateAll(Driver driver) {
		this.sqlSessionTemplate.update("com.huoyun.car.dao.DriverDaoMapper.updateAll", driver);
	}

	@Override
	public void updateRate(String rate, long count, long id) {
		// TODO Auto-generated method stub
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("rate", rate);
		map.put("id", id);
		map.put("count", count);
		this.sqlSessionTemplate.update("com.huoyun.car.dao.DriverDaoMapper.updateRate", map);
	}

	public Driver getDriverById(long driverId) {
		return this.sqlSessionTemplate.selectOne("com.huoyun.car.dao.DriverDaoMapper.getDriverById", driverId);
	}

	public void delete(long driverId) {
		this.sqlSessionTemplate.delete("com.huoyun.car.dao.DriverDaoMapper.delete", driverId);
	}

	@Override
	public List<Driver> getDriverByUserId(long userId) {
		return this.sqlSessionTemplate.selectList("com.huoyun.car.dao.DriverDaoMapper.getDriverByUserId", userId);
	}

	@Override
	public List<Driver> getDriverListByUsername(String username) {
		return this.sqlSessionTemplate.selectList("com.huoyun.car.dao.DriverDaoMapper.getDriverListByUsername", username);
	}

	@Override
	public Driver getDriverByIdCardNumber(long userId, String driverIdCardNumber) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userId", userId);
		map.put("driverIdCardNumber", driverIdCardNumber);
		return this.sqlSessionTemplate.selectOne("com.huoyun.car.dao.DriverDaoMapper.getDriverByIdCardNumber", map);
	}

	@Override
	public Driver getDriverByDrivingLicenseNumber(long userId, 
			String driverDrivingLicenseNumber) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userId", userId);
		map.put("driverDrivingLicenseNumber", driverDrivingLicenseNumber);
		return this.sqlSessionTemplate.selectOne("com.huoyun.car.dao.DriverDaoMapper.getDriverByDrivingLicenseNumber", map);
	}
}
